package org.example.bookstore.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.pojo.DO.Book;
import org.example.bookstore.service.BookService;
import org.example.bookstore.service.impl.BookServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "书本Api")
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/books")
public class BookController {

    @Autowired
    private BookService bookService;
    /*
     * 查询书本列表
     * */
    @Operation(summary = "查询商品列表")
    @GetMapping("/list")
    public ResultVO<?> selectGoods(@Parameter(name = "type", description = "类型")  @RequestParam(required = false) String type ,
                                   @Parameter(name = "page", description = "页数")  @RequestParam(defaultValue = "1") Integer page,
                                   @Parameter(name = "pageSize", description = "页面大小")  @RequestParam(defaultValue = "15") Integer pageSize){
        return ResultVO.success("获取商品数据成功", bookService.selectBooks(type,page,pageSize));

    }
    /*
     * 查询书本类型总数
     * */
    @Operation(summary = "搜索")
    @GetMapping("/search")
    public ResultVO<?> selectGoodsSum(@Parameter(name = "content", description = "搜索内容")  String content ){
        return ResultVO.success("查询商品成功", bookService.SearchGoods(content));
    }
    /*
     * 模糊搜索
     * */
    @Operation(summary = "查询商品总数")
    @GetMapping("/lisSum")
    public ResultVO<?> SearchGoods(@Parameter(name = "type", description = "类型") @RequestParam(required = false)   String type ){
        return ResultVO.success("获取书本总数成功", bookService.selectGoodsSum(type));
    }
    /*
     * 根据书本id来查询
     * */
    @Operation(summary = "查询书本详情")
    @GetMapping("/detail")
    public ResultVO<Book> selectGood(@Parameter(name = "id", description = "商品id") @RequestParam Integer id){
        return ResultVO.success("成功获取商品详情",bookService.selectBookById(id));
    }
    /*
     * 根本书本根据数组查询商品列表
     * */
    @Operation(summary = "根据数组查询书本列表")
    @PostMapping("/ArrayList")
    public ResultVO<?> selectBooksListByArray(@RequestBody List<Integer> ids){
        return  ResultVO.success("商品获取成功",bookService.selectBooksByIds(ids));
    }
    /*
     * 管理员权限
     * 删除书本
     * */
    @Operation(summary = "根据id删除书本")
    @DeleteMapping("/delete")
    public ResultVO<?> deleteBook(@Parameter(name = "id", description = "商品id") @RequestParam Integer id){
        return bookService.deleteBookById(id);
    }
    /*
     * 管理员权限
     * 新增书本
     * */
    @Operation(summary = "书本添加")
    @PutMapping("/add")
    public ResultVO<?>  addBook(@RequestBody Book book){
        return bookService.addBook(book);
    }
    /*
     * 管理员权限
     * 修改书本信息
     * */
    @Operation(summary = "书本修改")
    @PutMapping("/update")
    public ResultVO<?>  updateBook(@RequestBody Book book){
        return bookService.updateBook(book);
    }
    /*
     * 首页信息查询
     * 书本总数，用户总数，借阅书本总数，销售书本总数
     * */
    @Operation(summary = "总信息展示")
    @GetMapping("/allData")
    public ResultVO<?>  selectAllData(){
        return bookService.selectDates();
    }

}
